<?php
// mod文件只能被入口文件引用，不能直接访问
if(!defined('IN_DISCUZ')) {
	exit('Access Denied');
}

$subject_list = array();
$subject_list['mother'] = '孕妈妈身体变化';
$subject_list['father'] = '准爸爸爱妻行动';
$subject_list['noticeinfo'] = '孕期注意事项';
$subject_list['nutrition'] = '营养与保健';
$subject_list['antenatal'] = '胎教';
$subject_list['pregnancyfood'] = '每周推荐孕妇食谱';


$subject_list['babygrowth'] = '宝宝成长发育';
$subject_list['yuer'] = '妈妈育儿经';
$subject_list['babydisease'] = '宝宝常见疾病防治';
$subject_list['dailycare'] = '宝宝日常护理';
$subject_list['babyteacher'] = '幼儿教育';
$subject_list['babyimportant'] = '宝宝大事记';
$subject_list['importantnote'] = '妈妈特别关注';

$topicid = $_G["gp_topicid"];
$subject = $_G["gp_subject"];
$articleid = $_G["gp_articleid"];


$subject = !in_array($subject, array_keys($subject_list)) ? 'mother' : $subject;
$paragraph_title = $subject_list[$subject];

$paragraph_list = array();

$min_article_id = 65535;
$max_article_id = 0;
if(!isset($paragraph_list) || !is_array($paragraph_list) || count($paragraph_list) == 0){
	$sql = " select  t.id,t.title as week_name,a.id article_id,t.id - 47 as pic_id, a.title as article_title,p.title,p.content 
from t_topic t, t_article a, t_paragraph p 
where t.id = a.topic_id and a.id = p.article_id and a.title like '%$paragraph_title' and trim(p.content) != '' ";

	$query = DB::query($sql.' order by article_id');
	while($row = DB::fetch($query)) {
		$paragraph_list[$row['article_id']] =  $row;
		
		if( $row['article_id'] < $min_article_id) {
			$min_article_id = $row['article_id'];
		}
		
		if( $row['article_id'] > $max_article_id) {
			$max_article_id = $row['article_id'];
		}
	}
	DB::free_result($query);
}

if(!isset($articleid) || $articleid > $max_article_id || $articleid < $min_article_id ) {
	if( count($paragraph_list) > 0 ){
		$articleid = $min_article_id;
	}
	else {
		$articleid = 8;
	}
}

$paragraph = $paragraph_list[$articleid];


$pre_article_id = $articleid - 1;
$next_article_id = $articleid + 1;

$show_pre_article = false;
$show_next_article = false;

// 该topic文章数量不为空。
if(count($paragraph_list) > 0 ){
	if ($articleid > $min_article_id ){
		$show_pre_article = true;
	}
	if ($articleid < $max_article_id ){
		$show_next_article = true;
	}
}


include_once template("expert/viewtext");

?>